package com.whq.thrift.api.web.admin.db.methodinfo;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface MethodInfoMapper {
	@Select("select * from t_method_info where method_name=#{methodName}")
	@Results(value = { @Result(property = "id", column = "id"), @Result(property = "methodName", column = "method_name"),
			@Result(property = "updateTime", column = "update_time"), @Result(property = "isTob", column = "is_2b"),
			@Result(property = "needVerifyTicket", column = "need_verify_ticket"), 
			@Result(property = "verifyModuleId", column = "verify_module_id"), @Result(property = "signatureIgnoreParams", column = "signature_ignore_params"),
			@Result(property = "methodStatus", column = "method_status"), @Result(property = "introFunc", column = "intro_func"),
			@Result(property = "introRequestParams", column = "intro_request_params"), @Result(property = "introResponse", column = "intro_response"),
			@Result(property = "introDeveloper", column = "intro_developer"), @Result(property = "introComment", column = "intro_comment"),
			@Result(property = "createTime", column = "create_time"), 

			@Result(property = "verifyModuleMethod", column = "verify_module_method"), @Result(property = "timeoutMs", column = "timeout_ms"),
			@Result(property = "maxRunCountPreSecond", column = "max_run_count_pre_second"), @Result(property = "methodModuleId", column = "method_module_id") })
	public MethodInfo getMethodByName(@Param("methodName") String methodName);

	@Select("select * from t_method_info where id=#{id}")
	@Results(value = { @Result(property = "id", column = "id"), @Result(property = "methodName", column = "method_name"),
			@Result(property = "updateTime", column = "update_time"), @Result(property = "isTob", column = "is_2b"),
			@Result(property = "needVerifyTicket", column = "need_verify_ticket"), 
			@Result(property = "verifyModuleId", column = "verify_module_id"), @Result(property = "signatureIgnoreParams", column = "signature_ignore_params"),
			@Result(property = "methodStatus", column = "method_status"), @Result(property = "introFunc", column = "intro_func"),
			@Result(property = "introRequestParams", column = "intro_request_params"), @Result(property = "introResponse", column = "intro_response"),
			@Result(property = "introDeveloper", column = "intro_developer"), @Result(property = "introComment", column = "intro_comment"),
			@Result(property = "createTime", column = "create_time"), 
			@Result(property = "verifyModuleMethod", column = "verify_module_method"), @Result(property = "timeoutMs", column = "timeout_ms"),
			@Result(property = "maxRunCountPreSecond", column = "max_run_count_pre_second"), @Result(property = "methodModuleId", column = "method_module_id") })
	public MethodInfo getMethodById(@Param("id") int id);

	@Insert("INSERT INTO t_method_info " + " (method_name, update_time, "
			+ "is_2b, need_verify_ticket, verify_module_id,signature_ignore_params,"
			+ "method_status,intro_func,intro_request_params,intro_response,intro_developer,intro_comment,"
			+ "create_time,verify_module_method, timeout_ms, max_run_count_pre_second, method_module_id) " + " VALUES "
			+ " (#{methodName}, #{updateTime}, #{isTob}, #{needVerifyTicket}, #{verifyModuleId}, #{signatureIgnoreParams}"
			+ ", #{methodStatus}, #{introFunc}, #{introRequestParams}, #{introResponse}, #{introDeveloper}, #{introComment}"
			+ ", #{createTime}, #{verifyModuleMethod}, #{timeoutMs}, #{maxRunCountPreSecond}, #{methodModuleId}" + ")")
	public void addMethod(MethodInfo methodInfo);

	@SelectProvider(type = MethodInfoSqlProvider.class, method = "getByNameMethodsSql")
	@Results(value = { @Result(property = "id", column = "id"), @Result(property = "methodName", column = "method_name"),
			@Result(property = "updateTime", column = "update_time"), @Result(property = "isTob", column = "is_2b"),
			@Result(property = "needVerifyTicket", column = "need_verify_ticket"), 
			@Result(property = "verifyModuleId", column = "verify_module_id"), @Result(property = "signatureIgnoreParams", column = "signature_ignore_params"),
			@Result(property = "methodStatus", column = "method_status"), @Result(property = "introFunc", column = "intro_func"),
			@Result(property = "introRequestParams", column = "intro_request_params"), @Result(property = "introResponse", column = "intro_response"),
			@Result(property = "introDeveloper", column = "intro_developer"), @Result(property = "introComment", column = "intro_comment"),
			@Result(property = "createTime", column = "create_time"), 
			@Result(property = "verifyModuleMethod", column = "verify_module_method"), @Result(property = "timeoutMs", column = "timeout_ms"),
			@Result(property = "maxRunCountPreSecond", column = "max_run_count_pre_second"), @Result(property = "methodModuleId", column = "method_module_id") })
	public List<MethodInfo> findMethodsByIdMap(Map<String, Object> whereParams);

	@SelectProvider(type = MethodInfoSqlProvider.class, method = "getSelectCountSql")
	public int findMethodsCount(Map<String, Object> whereParams);

	@UpdateProvider(type = MethodInfoSqlProvider.class, method = "getUpdateSql")
	public void updMethod(MethodInfo methodInfo);

	@Delete("delete from t_method_info where id=#{id}")
	public void delMethod(@Param("id") Integer id);

	@Select("select * from t_method_info")
	@Results(value = { 
			@Result(property = "id", column = "id"),
			@Result(property = "methodName", column = "method_name"),
			@Result(property = "updateTime", column = "update_time"), 
			@Result(property = "isTob", column = "is_2b"),
			@Result(property = "needVerifyTicket", column = "need_verify_ticket"),
			@Result(property = "verifyModuleId", column = "verify_module_id"),
			@Result(property = "signatureIgnoreParams", column = "signature_ignore_params"),
			@Result(property = "methodStatus", column = "method_status"), 
			@Result(property = "introFunc", column = "intro_func"),
			@Result(property = "introRequestParams", column = "intro_request_params"),
			@Result(property = "introResponse", column = "intro_response"),
			@Result(property = "introDeveloper", column = "intro_developer"),
			@Result(property = "introComment", column = "intro_comment"),
			@Result(property = "createTime", column = "create_time"),
			@Result(property = "verifyModuleMethod", column = "verify_module_method"), 
			@Result(property = "timeoutMs", column = "timeout_ms"),
			@Result(property = "maxRunCountPreSecond", column = "max_run_count_pre_second"),
			@Result(property = "methodModuleId", column = "method_module_id") })
	public List<MethodInfo> findAllMethodInfo();
	
	@SelectProvider(type = MethodInfoSqlProvider.class, method = "findApiInfoList")
	@Results(value = { 
			@Result(property = "id", column = "id"),
			@Result(property = "methodName", column = "method_name"),
			@Result(property = "updateTime", column = "update_time"), 
			@Result(property = "isTob", column = "is_2b"),
			@Result(property = "needVerifyTicket", column = "need_verify_ticket"),
			@Result(property = "verifyModuleId", column = "verify_module_id"),
			@Result(property = "signatureIgnoreParams", column = "signature_ignore_params"),
			@Result(property = "methodStatus", column = "method_status"), 
			@Result(property = "introFunc", column = "intro_func"),
			@Result(property = "introRequestParams", column = "intro_request_params"),
			@Result(property = "introResponse", column = "intro_response"),
			@Result(property = "introDeveloper", column = "intro_developer"),
			@Result(property = "introComment", column = "intro_comment"),
			@Result(property = "createTime", column = "create_time"),
			@Result(property = "verifyModuleMethod", column = "verify_module_method"), 
			@Result(property = "timeoutMs", column = "timeout_ms"),
			@Result(property = "maxRunCountPreSecond", column = "max_run_count_pre_second"),
			@Result(property = "methodModuleId", column = "method_module_id") })
	public List<MethodInfo> findApiInfoList(Map<String, Object> whereParams);
}
